package maumau;

import java.util.*;

public class MauMau_State {
    private Vector<Integer> cards;
	private int topCard;
	private int topCardCol;
	private int topCardMult;
	private Vector<Integer> nrCardsOpponents;
	
	MauMau_State() {	};
	
	MauMau_State(Vector<Integer> c) {
		cards = c;
	};
	
	MauMau_State(int k1, int k2, int k3, int k4, int k5) {
		cards = new Vector<Integer>();
		cards.add(k1);
		cards.add(k2);
		cards.add(k3);
		cards.add(k4);
		cards.add(k5);
	};
	
	MauMau_State(MauMau_State s) {
		cards = s.cards;
		topCard = s.topCard;
		topCardMult = s.topCardMult;
		nrCardsOpponents = s.nrCardsOpponents;
	};
	
	// Number of Cards in Hand
	int getNrCards() {
		return cards.size();
	}
	
	// Get specific card. Numbering starts at 0
	Integer getCard(int n) {
		return cards.get(n % getNrCards());
	}
	
	// Get all cards
	Vector<Integer> getAllCards() {
		return cards;
	}
	
	// Get/set top open card and multiplier
	Integer getOpenCard() {
		return topCard;
	}
	int getOpenCardMult() {
		return topCardMult;
	}
	void setOpenCard(Integer c, int col, int m) {
		topCard = c;
		topCardCol = col;
		topCardMult = m;
	}
	
	// Get number of oponent cards. number of oponents starts at 0 which is closes player in current playing order
	int getNrCardsOponents(int n) {
		return nrCardsOpponents.get(n % 3);
	}
	void setNrCardsOponents(int c1, int c2, int c3) {
		nrCardsOpponents = new Vector<Integer>();
		nrCardsOpponents.add(c1);
		nrCardsOpponents.add(c2);
		nrCardsOpponents.add(c3);
	}
	
	// Return name of card
	public String getCardName(Integer k) {
		if(k < 32)
			return MauMau_Constants.FARBEN[getCardColor(k)] + " " + MauMau_Constants.NAMES[getCardType(k)];
		else
			return "Wunsch Bube ";
	}
	
	// Returns HERZ, PIK, KARO, KREUZ
	public int getCardColor(int k) {
		return k % 4;
	}
	
	// Cards 7,8,9,10,Bube,Dame,K�nig,Ass are numbered from 0 to 7
	// see NAMES[]
	public int getCardType(int k) {
		return k / 4;
	}
	
	// Counts number of hand cards with specific color
	public int countColor(int c) {
		int cnt = 0;
		for(int i: cards)
			if(c == getCardColor(i))
				cnt++;
		return cnt;
	}
	
	// Counts number of hand cards with specific type
	public int countType(int t) {
		int cnt = 0;
		for(int i: cards)
			if(t == getCardType(i))
				cnt++;
		return cnt;
	}
	
	// Prints hand
	public void print() {
		System.out.print("  Karten Hand: ");
		for(Integer i : cards) {
			System.out.print(getCardName(i) + " ("+i+ "), ");
		}
		System.out.println();
		System.out.println("  Karte Stapel: " + getCardName(topCard) +"("+topCard+") (Color " +  MauMau_Constants.FARBEN[topCardCol] + "), Multiplikator " + topCardMult);
		System.out.print("  Anzahl Karten Mitspieler: ");
		if(nrCardsOpponents == null)
			System.out.println(" (leer)");
		else
			for(int i = 0; i < 3; i++) 
				System.out.print(getNrCardsOponents(i) + ", ");
		
		System.out.println();
	};
}
